package com.fenghuajueli.libbasecoreui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fenghuajueli.libbasecoreui.R;
import com.fenghuajueli.libbasecoreui.constants.AppConfigInfo;
import com.fenghuajueli.libbasecoreui.constants.ConfigConstants;
import com.fenghuajueli.libbasecoreui.listener.OnCommentDialogListener;
import com.fenghuajueli.libbasecoreui.utils.MmkvUtils;
import com.fenghuajueli.libbasecoreui.constants.KVConstants;
import com.fenghuajueli.libbasecoreui.data.entity.comment.SwitchCommentEntity;

/**
 * 评论提示对话框
 */
public class CommentTipsDialog extends Dialog {

    private TextView tvTitle;
    private TextView tvContent;
    private TextView btnAction1;
    private TextView btnAction2;
    private TextView btnAction3;
    private SwitchCommentEntity switchCommentEntity;
    private OnCommentDialogListener onCommentDialogListener;


    public CommentTipsDialog(@NonNull Context context, SwitchCommentEntity switchCommentEntity) {
        super(context, R.style.StyleBaseDialog);
        this.switchCommentEntity = switchCommentEntity;

    }

    public void setOnCommentDialogListener(OnCommentDialogListener onCommentDialogListener) {
        this.onCommentDialogListener = onCommentDialogListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comment_tips_dialog_layout);
        tvTitle = findViewById(R.id.tvTitle);
        tvContent = findViewById(R.id.tvContent);
        btnAction1 = findViewById(R.id.btnAction1);
        btnAction2 = findViewById(R.id.btnAction2);
        btnAction3 = findViewById(R.id.btnAction3);
        if (switchCommentEntity == null) {
            switchCommentEntity = new SwitchCommentEntity();
            if (AppConfigInfo.CHANNEL.toUpperCase().equals(ConfigConstants.CHANNEL.HUAWEI.name())) {
                switchCommentEntity.setId(8);
                switchCommentEntity.setMsg1("提示");
                switchCommentEntity.setMsg2("您愿意用评分支持我们吗？");
                switchCommentEntity.setMsg3("继续使用");
                switchCommentEntity.setMsg4("立即评分");
            } else {
                switchCommentEntity.setId(7);
                switchCommentEntity.setMsg1("提示");
                switchCommentEntity.setMsg2("如果您觉得app还可以，请给个五星好评，谢谢！");
                switchCommentEntity.setMsg3("任性购买");
                switchCommentEntity.setMsg4("五星好评");
            }
            switchCommentEntity.setMsg5("任性购买");
        }
        tvTitle.setText(switchCommentEntity.getMsg1());
        tvContent.setText(switchCommentEntity.getMsg2());
        if (switchCommentEntity.getId() == 8) {
            //华为市场
            btnAction1.setText(switchCommentEntity.getMsg3());
            btnAction2.setText(switchCommentEntity.getMsg4());
            btnAction3.setText(switchCommentEntity.getMsg5());
            btnAction1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (switchCommentEntity.getMsg3().contains("继续使用")) {
                        if (onCommentDialogListener != null) {
                            onCommentDialogListener.goKeepUse();
                        }
                        dismiss();
                    }
                }
            });
            btnAction2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (switchCommentEntity.getMsg4().contains("立即评分")) {
                        if (onCommentDialogListener != null) {
                            onCommentDialogListener.goComment();
                        }
                        MmkvUtils.mmkv.encode(KVConstants.ALREADY_COMMENT, true);
                        dismiss();
                    }
                }
            });
            btnAction3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (switchCommentEntity.getMsg5().contains("任性购买")) {
                        if (onCommentDialogListener != null) {
                            onCommentDialogListener.goBuyVip();
                        }
                        dismiss();
                    }
                }
            });
        } else {
            btnAction1.setVisibility(View.GONE);
            btnAction2.setText(switchCommentEntity.getMsg4());
            btnAction3.setText(switchCommentEntity.getMsg5());
            btnAction2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (switchCommentEntity.getMsg4().contains("五星好评")) {
                        if (onCommentDialogListener != null) {
                            onCommentDialogListener.goComment();
                        }
                        MmkvUtils.mmkv.encode(KVConstants.ALREADY_COMMENT, true);
                        dismiss();
                    }
                }
            });
            btnAction3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (switchCommentEntity.getMsg5().contains("任性购买")) {
                        if (onCommentDialogListener != null) {
                            onCommentDialogListener.goBuyVip();
                        }
                        dismiss();
                    }
                }
            });
        }

    }


    @Override
    public void dismiss() {
        super.dismiss();
    }
}
